package com.useeinfo.oa.modules.security.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.CommonSugar;

import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.util.Set;

/**
 */
@Entity
@Table(name = "system_resource")
public
class SystemResource extends SuperClassEntity<SystemResource> {

	private String resourceName;
	private String resourceDescription;
	private String resourceType;
	private String resourceString;
	@ManyToMany(mappedBy = "resourceSet")
	private Set<SystemAuthority> authoritySet;
	private boolean systemManager;
	private boolean enabled;

	@Override
	public JSONObject toJSONObject() {
		JSONObject jsonObject = new JSONObject();

		jsonObject.put("resourceId", CommonSugar.getTypedDefault(getId(), 0L));
		jsonObject.put("resourceName", CommonSugar.getTypedDefault(getResourceName(), ""));
		jsonObject.put("resourceDescription", CommonSugar.getTypedDefault(getResourceDescription(), ""));
		jsonObject.put("resourceType", CommonSugar.getTypedDefault(getResourceType(), ""));
		jsonObject.put("resourceString", CommonSugar.getTypedDefault(getResourceString(), ""));
		jsonObject.put("systemManager", isSystemManager());
		jsonObject.put("enabled", isEnabled());

		return jsonObject;
	}

	public String getResourceName() {
		return resourceName;
	}

	public void setResourceName(String resourceName) {
		this.resourceName = resourceName;
	}

	public String getResourceDescription() {
		return resourceDescription;
	}

	public void setResourceDescription(String resourceDescription) {
		this.resourceDescription = resourceDescription;
	}

	public String getResourceType() {
		return resourceType;
	}

	public void setResourceType(String resourceType) {
		this.resourceType = resourceType;
	}

	public String getResourceString() {
		return resourceString;
	}

	public void setResourceString(String resourceString) {
		this.resourceString = resourceString;
	}

	public Set<SystemAuthority> getAuthoritySet() {
		return authoritySet;
	}

	public void setAuthoritySet(Set<SystemAuthority> authoritySet) {
		this.authoritySet = authoritySet;
	}

	public boolean isSystemManager() {
		return systemManager;
	}

	public void setSystemManager(boolean systemManager) {
		this.systemManager = systemManager;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
}
